const toastTrigger = document.querySelector(".my-toast")
const toastLiveExample = document.querySelector('.toast-body')
const toast = new bootstrap.Toast(toastTrigger)


document.querySelector('#btn-register').addEventListener("click", async function(){
	const username = document.querySelector('[name = "username"]').value
	const password = document.querySelector('[name = "password"]').value
	// console.log(username,password);
	// console.log(111);
	if(username.trim() === "" || password === ""){
		toastLiveExample.innerText = '请输入用户名或密码'
		toast.show()
		return 
	}
	
	if(username.trim().length < 8 || username.trim().length > 30 || password.trim().length < 6 || password.trim().length > 30 ){
		toastLiveExample.innerText = '用户名8-30个字符，密码6-30个字符'
		toast.show()
		return
	}
	
	try{
		const res = await axios({
			url:"/register",
			method:"post",
			data:{
				username,password
			}
		})
		
		toastLiveExample.innerText = '注册成功'
		toast.show()
	}catch(e){
		//TODO handle the exception
		console.log(e);
	}
})